<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head th:replace="common/header::common_head"></head>
<link rel="stylesheet" href="../bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
<title>仓库查询</title>
<style type="text/css">
    .shadow{
        width:100%;
        height:100%;
        position:absolute;
        left:0;
        top:0;
        z-index:998;
        background-color:gainsboro;
        opacity:0.6;
        display:none;
    }
    #addStore{
        position:fixed;
        z-index:999;
        display:none;
        top: 30%;
        left: 40%;

    }
    #editStore{
        position:fixed;
        z-index:999;
        display:none;
        top: 30%;
        left: 40%;

    }
    #editGroup{
        position:fixed;
        z-index:999;
        display:none;
        top: 30%;
        left: 40%;

    }
    #addTd{
        float: right;
        margin: 15px;
    }
</style>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <div th:replace="common/LeftCommon::common_top_left"></div>

    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                仓库管理
            </h1>
            <ol class="breadcrumb">
                <li><a href="/index"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">仓库</a></li>
                <li class="active">仓库管理</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <div class="box-tools">
                                <div class="input-group input-group-sm" style="width: 150px;">
                                    <input type="text" name="table_search" id="search"  class="form-control pull-right" placeholder="查询仓库名字">

                                    <div class="input-group-btn">
                                        <button type="submit" class="btn btn-default" onclick="search()" id="btn"><i class="fa fa-search"></i></button>
                                    </div>
                                </div>
                            </div>
                            <div style="float: left">
                                <button type="button" class="btn btn-block btn-info" onclick="addStoreDiv()">增加用户</button>
                            </div>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover">
                                <thead>
                                <tr>
                                    <th>操作</th>
                                    <th>仓库名称</th>
                                    <th>负责人</th>
                                    <th>所属门店</th>
                                    <th>备注</th>
                                    <th>创建时间</th>
                                    <th>更新时间</th>
                                    <th>排序</th>
                                    <th>状态</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr th:each="storeHouse,storeStart : ${pageInfo.getList()}">
                                    <td><a  href="javascript:void(0)" th:onclick="'javascript:editStoreDiv(\''+ ${storeHouse.storeId} + '\')'" class="label label-primary">编辑</a>
                                        <a href="javascript:void(0)" th:onclick="'javascript:deleteStore(\''+ ${storeHouse.storeId} + '\')'" class="label label-danger">删除</a>
                                    </td>
                                    <td th:text="${storeHouse.storeName}"></td>
                                    <td th:text="${storeHouse.userName}"></td>
                                    <td th:text="${storeHouse.shopName}"></td>
                                    <td th:text="${storeHouse.remarks}"></td>
                                    <td th:text="${#dates.format(storeHouse.createTime, 'yyyy-MM-dd  HH:mm:ss')}"></td>
                                    <td th:text="${#dates.format(storeHouse.updateTime, 'yyyy-MM-dd  HH:mm:ss')}"></td>
                                    <td th:text="${storeHouse.sort}"></td>
                                    <td th:if="${storeHouse.storeStatus} == true">&nbsp;&nbsp;启用</td>
                                    <td th:if="${storeHouse.storeStatus} == false">&nbsp;&nbsp;关闭</td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                        <!-- /.box-body -->
                        <!-- 分页-->
                        <div class="box-footer clearfix">
                            <ul class="pagination pagination-sm no-margin pull-right">
                                <li th:if="${pageInfo.isFirstPage}" class="disabled"><a href="#">&laquo;</a></li>
                                <li th:unless="${pageInfo.isFirstPage}"><a th:href="@{/stock/management(page=${pageInfo.prePage})}">&laquo;</a></li>
                                <li th:each="index : ${#numbers.sequence(1,pageInfo.pages)}">
                                    <a  th:href="@{/stock/management(page=${index})}" th:text="${index}"></a>
                                </li>
                                <li th:if="${pageInfo.isLastPage}" class="disabled"><a href="#">&raquo;</a></li>
                                <li th:unless="${pageInfo.isLastPage}"><a th:href="@{/stock/management(page=${pageInfo.nextPage})}">&raquo;</a></li>
                            </ul>
                        </div>
                    </div>
                    <!-- /.box -->
                </div>
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <footer class="main-footer">
        <div class="pull-right hidden-xs">
            <b>Version</b> 2.4.0
        </div>
        <strong>Copyright &copy; 2014-2016 <a href="https://adminlte.io">Almsaeed Studio</a>.</strong> All rights
        reserved.
    </footer>

    <div class="control-sidebar-bg"></div>
    <div class="shadow"></div>
    <div id="addStore" style="width: 25%;" >
        <div class="row">
            <div class="col-xs-12">
                <div style="height: 40px; background: #0b97c4; text-align: center"><p style="font-size: larger"><b>增加仓库</b></p></div>
                <form style="background: white" id="store" method="post">
                    <table>
                        <tr>
                            <td class="col-xs-7" id="addTd">仓库名称：</td>
                            <td class="col-xs-5"><input name="storeName" placeholder="仓库名称" id="storeName"></td>
                        </tr>
                        <tr>
                            <td class="col-xs-7" id="addTd">仓库负责人：</td>
                            <td class="col-xs-5">
                                <select name="userId">
                                    <option th:each="Manager:${Managers}" th:value="${Manager.userId}" th:text="${Manager.userName}"></option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="col-xs-7" id="addTd">所属门店:</td>
                            <td class="col-xs-5">
                                <select name="shopId">
                                    <option value="12">无门店,后期在增加</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="col-xs-7" id="addTd">启用:</td>
                            <td class="col-xs-5">
                                <select name="storeStatus">
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="col-xs-7" id="addTd">备注：</td>
                            <td class="col-xs-5"><input name="remarks" placeholder="备注" id="remarks"></td>
                        </tr>
                        <tr>
                            <td class="col-xs-7" id="addTd">排序：</td>
                            <td class="col-xs-5"><input name="sort" placeholder="1-100之间" id="sort"></td>
                        </tr>
                        <tr>
                            <td class="col-xs-6" id="addTd"><button th:onclick="addStore()" >确定</button></td>
                            <td class="col-xs-6" style="margin: 0 auto"><button th:onclick="hideShadow()" >取消</button></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </div>
    <div id="editStore" style="width: 25%;" >
        <div class="row">
            <div class="col-xs-12">
                <div style="height: 40px; background: #0b97c4; text-align: center"><p style="font-size: larger"><b>增加仓库</b></p></div>
                <form style="background: white" id="estore"  method="post">
                    <table>
                        <tr>
                            <td class="col-xs-7" id="addTd">仓库名称：</td>
                            <td class="col-xs-5"><input name="storeName" placeholder="仓库名称" id="estoreName"></td>
                        </tr>
                        <tr>
                            <td class="col-xs-7" id="addTd">仓库负责人：</td>
                            <td class="col-xs-5">
                                <select name="userId" id="euserId">
                                    <option th:each="Manager:${Managers}" th:value="${Manager.userId}" th:text="${Manager.userName}"></option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="col-xs-7" id="addTd">所属门店:</td>
                            <td class="col-xs-5">
                                <select name="shopId" id="eshopId">
                                    <option value="12">test</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="col-xs-7" id="addTd">启用:</td>
                            <td class="col-xs-5">
                                <select name="storeStatus" id="estoreStatus">
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="col-xs-7" id="addTd">备注：</td>
                            <td class="col-xs-5"><input name="remarks" placeholder="备注" id="eremarks"></td>
                        </tr>
                        <tr>
                            <td class="col-xs-7" id="addTd">排序：</td>
                            <td class="col-xs-5"><input name="sort" placeholder="1-100之间" id="esort"></td>
                        </tr>
                        <input id="estoreId" type="hidden" name="storeId" >
                        <tr>
                            <td class="col-xs-6" id="addTd"><button th:onclick="editStore()" >确定</button></td>
                            <td class="col-xs-6" style="margin: 0 auto"><button th:onclick="hideShadow()">取消</button></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- ./wrapper -->

<!-- jQuery 3 -->
<script src="../../bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="../../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="../../bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="../../bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="../../bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="../../bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="../../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../dist/js/demo.js"></script>
<!-- page script -->
<script>
    $(function () {
        $('#example1').DataTable()
        $('#example2').DataTable({
            'paging'      : true,
            'lengthChange': false,
            'searching'   : false,
            'ordering'    : true,
            'info'        : true,
            'autoWidth'   : false
        })
    })
    // 添加仓库
    function addStore() {
        $.ajax({
            url: "/store_management/addStore",
            type: "POST",
            data: $("#store").serialize(),
            success:function (data) {
                if (data.code == 1) {
                    window.location.href = "/stock/management";
                    alert("修改成功");
                } else {
                    alert(data.msg);
                }
            }
        });
    }
    // 打开增加仓库框
    function addStoreDiv() {
        $(".shadow").css({'display':'block'});
        $("#addStore").show();
        return 0;
    }
    // 删除仓库
    function deleteStore(storeId) {
        $.ajax({
            url:"/store_management/deleteStore",
            type:'POST',
            data:{
                storeId:storeId
            },
            success:function (data) {
                if (data.code == 1) {
                    window.location.href ="/stock/management";
                    alert("删除成功");
                } else {
                    alert(data.msg);
                }
            }
        })
    }
    // 打开编辑仓库框
    function editStoreDiv(storeId) {
        if (storeId == null) {
            alert("未知错误");
            return 0;
        }
        $.ajax({
            url:"/store_management/editStoreDiv",
            type:'GET',
            data:{
                storeId:storeId
        },
        success:function(data){
            $("#estoreId").val(data.storeId)
            $("#estoreName").val(data.storeName);
            $("#euserId").val(data.userId);
            $("#eshopId").val(data.shopId);
            $("#estoreStatus").val(data.storeStatus);
            $("#eremarks").val(data.remarks);
            $("#esort").val(data.sort);
            $(".shadow").css({'display':'block'});
            $("#editStore").show();
            return 0;
        }
        })
    }
    // 修改仓库
    function editStore() {
        $.ajax({
            url:"/store_management/editStore",
            type:'POST',
            data: $("#estore").serialize(),

            success:function (data) {
                if (data.code == 1) {
                    window.location.href = "/stock/management";
                    alert("修改成功");
                } else {
                    alert(data.msg);
                }
            }
        })
    }

    function search(){
            var sstxt=$('#search').val();
            $("table tbody tr")
                .hide()
                .filter(":contains('"+sstxt+"')")
                .show();
    }

    function hideShadow() {
        $(".shadow").css({'display':'none'});
        $('#addStore').hide();
        $('#editStore').hide();
        $("#store")[0].reset();
    }
</script>
</body>
</html>
